package com.qf.springwork.utils;

import cn.hutool.core.io.file.FileAppender;
import com.qf.springwork.entity.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;


public class UserWriter {

    private String filepath = "E:\\Program Files\\user.csv";

    public String getFilepath() {
        return filepath;
    }

    public void setFilepath(String filepath) {
        this.filepath = filepath;
    }

    public void userAddWriter(List<User> users){
        FileAppender appender = new FileAppender(new File(filepath),16,true);
        for (User user : users) {
            String csv = user.toCSVString();
            appender.append(csv);
        }
        appender.flush();
    }
}
